/**
 * 2013 2013-1-10
 */
package com.surfilter.platform.base.util;

import java.math.BigDecimal;

import org.apache.poi.hssf.usermodel.HSSFCell;

/**
 * @author Administrator 用于解析excel文件，生成json
 */
public class ExcelUtil {

	public static String getCellValue(HSSFCell cell) {
		String ret;
		switch (cell.getCellType()) {
		case HSSFCell.CELL_TYPE_NUMERIC:
			Double val = cell.getNumericCellValue();
			ret = val.toString();
			// 直接Double.toString 会用科学计数法表示，转成BigDecimal就不会
			if (ret.contains("E")) {
				BigDecimal bd = new BigDecimal(val);
				ret = bd.toString();
			} else if (ret.contains(".")) {
				ret = ret.replaceFirst("[.]\\d+$", "");
			}
			break;
		case HSSFCell.CELL_TYPE_STRING:
			ret = cell.getRichStringCellValue().getString();
			break;
		default:
			ret = "";
			break;
		}
		return ret;
	}
}
